<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 300px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        .message {
            margin-top: 15px;
            padding: 10px;
            border-radius: 4px;
            display: none;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .info {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>用户登录</h2>
        <div class="info">
            <strong>测试账号：</strong><br>
            用户名: admin<br>
            密码: admin<br>
            验证码: 1234
        </div>
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名:</label>
                <input type="text" id="username" name="username" required>
            </div>
            <div class="form-group">
                <label for="password">密码:</label>
                <input type="password" id="password" name="password" required>
            </div>
            <div class="form-group">
                <label for="captcha">验证码:</label>
                <input type="text" id="captcha" name="captcha" required>
                <small>默认验证码: 1234</small>
            </div>
            <button type="submit">登录</button>
        </form>
        
        <div id="message" class="message"></div>
        
        <div style="margin-top: 15px; text-align: center;">
            <a href="user.php" target="_blank">查看用户状态</a>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const messageDiv = document.getElementById('message');
            
            // 显示加载状态
            messageDiv.style.display = 'block';
            messageDiv.className = 'message info';
            messageDiv.innerHTML = '登录中...';
            
            // 发送AJAX请求
            fetch('login.php', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    messageDiv.className = 'message success';
                    messageDiv.innerHTML = data.message + ' 正在跳转...';
                    setTimeout(() => {
                        window.location.href = 'user.php';
                    }, 1000);
                } else {
                    messageDiv.className = 'message error';
                    messageDiv.innerHTML = data.message;
                }
            })
            .catch(error => {
                messageDiv.className = 'message error';
                messageDiv.innerHTML = '网络错误: ' + error;
            });
        });
    </script>
</body>
</html>